package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserApiController {

    @Autowired
    private UserAddressService userAddressService;

    @GetMapping("userAddress/auth/findUserAddressList")
    public Result findUserAddressList(HttpServletRequest request){
        //  select * from user_address where user_id = ?;
        //  获取用户Id  --> 不需要获取临时用户Id 访问这个地址则必须要登录！
        String userId = AuthContextHolder.getUserId(request);
        //  调用服务层方法.
        List<UserAddress> userAddressList = userAddressService.findUserAddressList(userId);
        return Result.ok(userAddressList);
    }
}
